package com.rwx.myjetpack.flow

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.rwx.myjetpack.R
import com.rwx.myjetpack.base.BaseActivity
import com.rwx.myjetpack.databinding.ActivityFlowPlayerBinding
import com.rwx.myjetpack.player.IPlayerCallback
import com.rwx.myjetpack.player.PlayerPresenter

class FlowPlayerActivity : BaseActivity()/*, IPlayerCallback*/ {

    val binding by lazy { ActivityFlowPlayerBinding.inflate(layoutInflater) }


    private val playerPresenter by lazy {
        PlayerPresenter.instance
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

       // playerPresenter.registerCallback(this)

        initListener()
        initDataChangeListener()

    }

    private fun initDataChangeListener() {

        playerPresenter.currentPlayState.addListener(this) {
            when(it){
                PlayerPresenter.PlayState.PAUSE->{
                    binding.playOrPauseBtn.text="播放"
                }
                PlayerPresenter.PlayState.PLAYING->{
                    binding.playOrPauseBtn.text="暂停"
                }
            }
        }
    }

    private fun initListener() {

        binding.playOrPauseBtn.setOnClickListener {
            playerPresenter.doPlayOrPause()
        }

    }

//    override fun onTitleChange(title: String) {
//
//    }

//    override fun onProgressChange(current: Int) {
//
//    }
//
//    override fun onPlaying() {
//        binding.playOrPauseBtn.text="暂停"
//    }
//
//    override fun onPlayPause() {
//        binding.playOrPauseBtn.text="播放"
//    }
//
//    override fun onCoverChange(cover: String) {
//
//    }


    override fun onDestroy() {
        super.onDestroy()
        //playerPresenter.unRegisterCallBack(this)
    }
}